package com.getpebble.android.main.sections.settings.adapter;

import android.content.Context;
import android.database.Cursor;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import com.getpebble.android.view.LanguagePackView;

public class LanguagePackAdapter extends CursorAdapter {
    private final String mIsoLocale;

    public LanguagePackAdapter(Context context, Cursor c, String isoLocale) {
        super(context, c, 0);
        this.mIsoLocale = isoLocale;
    }

    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        return new LanguagePackView(context);
    }

    public void bindView(View view, Context context, Cursor cursor) {
        if (view instanceof LanguagePackView) {
            LanguagePackView languagePackView = (LanguagePackView) view;
            String languageName = cursor.getString(cursor.getColumnIndex("local_language_name"));
            String isoLocale = cursor.getString(cursor.getColumnIndex("iso_locale"));
            languagePackView.setLanguageName(languageName);
            if (this.mIsoLocale != null && isoLocale != null && isoLocale.equalsIgnoreCase(this.mIsoLocale)) {
                languagePackView.setInstalled(true);
            }
        }
    }
}
